<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true"  label-width="98px">
      <el-form-item label="应用名称" prop="sequenceNumber">
        <el-input
          v-model="queryParams.sequenceNumber"
          placeholder="请输入应用名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="用户ID" prop="sequenceNumber">
        <el-input
          v-model="queryParams.sequenceNumber"
          placeholder="请输入用户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="用户姓名" prop="sequenceNumber">
        <el-input
          v-model="queryParams.sequenceNumber"
          placeholder="请输入用户姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="应用使用次数" prop="sequenceNumber">
        <el-input
          v-model="queryParams.sequenceNumber"
          placeholder="请输入应用使用次数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <br/>
      <div style="text-align: right;">
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" >搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery" >重置</el-button>
        </el-form-item>
      </div>

    </el-form>


    <el-table v-loading="loading" :data="contractList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />

      <el-table-column type="index" label="序号" width="55" :index="indexMethod" align="center" />
      <el-table-column label="序号" align="center" prop="id" v-if="columns[0].visible"/>
      <el-table-column label="用户ID" align="center" prop="userId" v-if="columns[1].visible"/>
      <el-table-column label="用户姓名" align="center" prop="username" v-if="columns[2].visible">

        <el-table-column label="应用ID" align="center" prop="menuId" v-if="columns[3].visible"/>
        <el-table-column label="应用名称" align="center" prop="menuname" v-if="columns[4].visible"/>
        <el-table-column label="使用次数" align="center" prop="frequency" v-if="columns[5].visible"/>


      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />







  </div>
</template>

<script>
import { listContract, getContract, delContract, addContract, updateContract } from "@/api/module/cjl/contract";
import { getToken } from "@/utils/auth";
import { treeselect } from "@/api/system/dept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
  name: "Contract",
  dicts: ['sys_job_status','yh_contract_type','yh_contract_declare','yh_item_classification','yh_representative_office','yh_equipment_contractor_unit','yh_contractor_unit'],
  components: { Treeselect },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 部门树选项
      deptOptions: undefined,
      // 合同台账表格数据
      contractList: [],
      // 岗位选项
      postOptions: [],
      // 部门名称
      deptName: undefined,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sequenceNumber: null,
        projectName: null,
        contractType: null,
        equipName: null,
        equipVersion: null,
        quantity: null,
        technicalConditions: null,
        contractNo: null,
        contractDeclare: null,
      },
      // 表单参数
      form: {},
      // 用户查询参数
      view:{
        // 是否显示弹出层（用户查询）
        open: false,
        // 弹出层标题（用户查询）
        title: "",
      },

      // 列信息
      columns: [
        { key: 0, label: `合同流水号`, visible: true },
        { key: 1, label: `项目名称`, visible: true },
        { key: 2, label: `合同类别`, visible: true },
        { key: 3, label: `装备名称`, visible: true },
        { key: 4, label: `装备型号`, visible: true },
        { key: 5, label: `数量`, visible: true },
        { key: 6, label: `技术状态`, visible: true },
      ],
      // 表单校验
      rules: {  sequenceNumber: [
          { required: true, message: "合同流水号不能为空", trigger: "blur" },
        ],
        contractType: [
          { required: true, message: "合同类别不能为空", trigger: "blur" },
        ],
        equipVersion: [
          { required: true, message: "装备型号不能为空", trigger: "blur" },
        ],
        contractNo: [
          { required: true, message: "合同编号不能为空", trigger: "blur" },
        ],
        managementAgency: [
          { required: true, message: "项目管理机构不能为空", trigger: "blur" },
        ],
        equipmentContractorUnit: [
          { required: true, message: "装备承制单位不能为空", trigger: "blur" },
        ],
        matchingContractNo: [
          { required: true, message: "配套合同/协议号不能为空", trigger: "blur" },
        ],
        contractorUnit: [
          { required: true, message: "承制单位不能为空", trigger: "blur" },
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getTreeselect();
  },
  methods: {
    /** 查询合同台账列表 */
    getList() {
      this.loading = true;
      listContract(this.queryParams).then(response => {
        this.contractList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then(response => {
        this.deptOptions = response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮
    viewCancel() {
      this.view.open = false;
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        sequenceNumber: null,
        projectName: null,
        contractType: null,
        equipName: null,
        equipVersion: null,
        quantity: null,
        technicalConditions: null,
        contractNo: null,
        contractDeclare: null,
        representativeOffice: null,
        regulation: null,
        projectType: null,
        purchasingDepartment: null,
        taskConfirmationTime: null,
        executiveStaff: null,
        taskStatus: "0",
        completionTime: null,
        note: null,
        paymentTime: null,
        managementAgency: null,
        equipmentContractorUnit: null,
        scheduleTarget: null,
        contractorUnit: null,
        matchingContractNo: null,
        generalRepresentativeOffice: null,
        generalContractorUnit: null,
        projectManagementAgency: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.is=selection.map(item => item.sequenceNumber)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加合同台账";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getContract(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改合同台账";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateContract(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addContract(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 详细按钮操作 */
    handleView(row) {
      const id = row.id || this.ids
      getContract(id).then(response => {
        this.form = response.data;
        this.view.open = true;
        this.view.title = "查看合同台账信息";
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      const i=row.sequenceNumber || this.is;
      this.$modal.confirm('是否确认删除合同流水号为"' + i + '"的数据项？').then(function() {
        return delContract(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('module/cjl/contract/export', {
        ...this.queryParams
      }, `contract_${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "合同台账信息导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('module/cjl/contract/importTemplate', {
      }, `contract_template_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    }
  }
};
</script>
<style>
.el-header, .el-footer {
  background-color: #FFFFFF;
  color: #333;
  text-align: left;
  line-height: 60px;
  font-style: oblique;

}

.el-aside {
  background-color: #D3DCE6;
  color: #333;
  text-align: center;
  line-height: 200px;
}
body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

/*对话框标题样式*/
.el-dialog__title{
  /*color: #1ab394;*/
  font-weight: bold;
  font-size: 25px;
}
</style>
